// pages/home/homeIndex/homeIndex.js
import { HomeIndex } from 'homeIndex-model.js';
import { Config } from '../../../utils/config.js';
var Function = require("../../../utils/function.js");
var index = new HomeIndex(); //实例化 首页 对象
var getUserInfo = require('../../auth/auth.js')
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
        //bannen
        imgUrls:[],

        close: true, //授权弹框
        bannerArr: [
              {
                    name: '五一放假通知',
              }, {
                    name: '五一放假通知',
              },{
                    name: '五一放假通知',
              }
        ],
        personal: [
              {
                    id: 0,
                    name: '缺卡提醒',
                    img: '/images/icon/home04.png',
                    url: '/pages/personal/remind/remind'
              }, {
                    id: 1,
                    name: '待我审批',
                    img: '/images/icon/home05.png',
                    url: '/pages/work/MyApproval/approval/approval?index=0'
              }, {
                    id: 2,
                    name: '通讯录',
                    img: '/images/icon/home06.png',
                    url: '/pages/personal/record/record'
              }, {
                    id: 3,
                    name: '个人认证',
                    img: '/images/icon/home07.png',
                    url: '/pages/personal/attestation/attestation'
              }
        ],
        check: [
              {
                    id: 0,
                    name: '考勤打卡',
                    img: '/images/icon/home08.png',
                    url: '/pages/home/clockIn/clockIn'
              }, {
                    id: 1,
                    name: '考勤统计',
                    img: '/images/icon/home09.png',
                    url: '/pages/home/statistics/statistics'
              }, {
                    id: 2,
                    name: '打卡日历',
                    img: '/images/icon/home10.png',
                    url: '/pages/home/calendar/calendar'
              }
        ],
        work: [
              {
                    id: 0,
                    name: '我审批的',
                    img: '/images/icon/home11.png',
                    url: '/pages/work/MyApproval/approval/approval?index=1'
              }, {
                    id: 1,
                    name: '我发起的',
                    img: '/images/icon/home12.png',
                    url: '/pages/work/MyLaunch/launch/launch'
              }, {
                    id: 2,
                    name: '请假',
                    img: '/images/icon/home13.png',
                    url: '/pages/work/Submit/suvacation/suvacation'
              }, {
                    id: 3,
                    name: '出差',
                    img: '/images/icon/home14.png',
                    url: '/pages/work/Submit/sutravel/sutravel'
              }, {
                    id: 4,
                    name: '补卡',
                    img: '/images/icon/home15.png',
                    url: '/pages/work/Submit/surepair/surepair'
              }
        ],
        statistics: [
              {
                    id: 0,
                    name: '我要预订',
                    img: '/images/icon/home16.png',
                    url: '/pages/meals/subscribe/subscribe'
              }, {
                    id: 1,
                    name: '我的预定',
                    img: '/images/icon/home17.png',
                    url: '/pages/meals/bookList/bookList'
              }, {
                    id: 2,
                    name: '用餐统计',
                    img: '/images/icon/home18.png',
                    url: '/pages/meals/census/census'
              }
        ],
  },

  //图片
  bindBanner(){
    let data = { id:1 }
    index.getBanner(data,res=>{
      this.setData({ imgUrls: res.data[0].items })
    })
  },

  //公告列表
  bindList(){
    index.getNotice({},(res)=>{
      this.setData({ bannerArr:res.data })
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
      onLoad: function (options) {
        this.bindList();
        this.bindBanner();
      },
      onReady: function () {
            // 页面首次渲染完毕时执行
            setTimeout(() => {
                  console.log(app.globalData.close)
                  let close = app.globalData.close
                  this.setData({
                        close: close
                  })
            },1000)
      },

      linkTo(e) {
            let url = Function.getDataSet(e, 'url');
            Function.linkTo(url)
      },

      //授权
      bindGetUserInfo: function(e) {
            getUserInfo.bindGetUserInfo(e)
            this.setData({
                  close: true
            })
      },

      refuse: function() {
            this.setData({
                  close: true
            })
      },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (ops) {
    if (ops.from === 'button') {
      // 来自页面内转发按钮
      console.log(ops.target)
    }
    return {
      title: 'xx小程序',
      path: 'pages/home/share/share',
      success: function (res) {
        // 转发成功
        console.log("转发成功:" + JSON.stringify(res));
      },
      fail: function (res) {
        // 转发失败
        console.log("转发失败:" + JSON.stringify(res));
      }
    }

  }
})